package org.example.javawebday1.utils;

import io.jsonwebtoken.Jwts;

import java.util.Date;
import java.util.Map;

public class JwtUtils {

    private static final long EXPIRATION_TIME = 60 * 60 * 1000;
    private static final String SECRET_KEY = "9f3a84989d157dc13a7abc467f128cf5c3d9e9d7e31656a2a89da76e686b5e82";

    public static String generateToken(Map<String, Object> map) {
        return Jwts.builder()
                .setClaims(map)
                .signWith(io.jsonwebtoken.SignatureAlgorithm.HS256,SECRET_KEY )
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
                .compact();
    }

    public static Map<String, Object> parseToken(String token) {
        return Jwts.parser()
                .setSigningKey(SECRET_KEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
